<?php
namespace app\common\model;

use Tinywan\Jwt\JwtToken;

/**
 * 用户信息模型
 */
class User extends BaseModel
{
    // 完整数据库表名称
    protected $table  = 'gii_user';
    // 主键
    protected $pk = 'id';

    const STATUS_NORMAL = 1;
    const STATUS_STOP   = 2;

    public static function getStatusTextList()
    {
        return [
            self::STATUS_NORMAL => "正常",
            self::STATUS_STOP   => "停用",
        ];
    }

    public static function createPwd($password, $salt)
    {
        return md5(md5($password) . $salt);
    }

    /**
     * Notes:登录生成token
     * @param $user //用户信息
     * @return array
     */
    public static function jwt($user, $client = JwtToken::TOKEN_CLIENT_MOBILE)
    {
        return JwtToken::generateToken([
            'id'     => $user['id'],
            'phone'  => $user['phone'],
            'client' => $client
        ]);
    }
}